perm filename LOGGER.MID[NET,MRC] blob sn#339546 filedate 1978-03-09 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00006 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	TITLE LOGGER
C00005 00003	Initialization
C00007 00004	Set up monitor pointers
C00009 00005	RFC server
C00012 00006	Subroutines
C00013 ENDMK
CāŠ—;
TITLE LOGGER
SUBTTL Definitions

; Mark Crispin, SU-AI, March 1978

; AC definitions

A=1 ? B=2 ? X=10 ? P=17

; Assembly switches

IFNDEF PDLLEN,PDLLEN==50		; length of pushdown stack

; SAIL system bit definitions

INTIMS==000020,,			; RFC arrived
RFCS==  200000,,			; RFC sent
RFCR==  100000,,			; RFC received
CLSS==  040000,,			; CLS sent
CLSR==  020000,,			; CLS received
LGONCE==004000,,			; here already
REAPRV==040000,,			; read anywhere
WRTPRV==020000,,			; write anywhere
ACWPRV==000040,,			; patch core
LUPPRV==000001,,			; local user

; Data area

CORBEG==.
PDL:	BLOCK PDLLEN			; pushdown stack
NOPRVP:	BLOCK 1				; -1 → cretin privileges have screwed us
COREND==.-1

; SWAP UUO block

SWPBLK:	'DSK,,				; device name
SVRNAM:	'RFC,,				; program name
	14				; phantom job
	0				; normal core size and start address
	'NETSYS				; file directory
	'NETSYS				; PPN to be run under

; Pointers into the monitor

JBTLIN:	BLOCK 1				; addr of our JBTLIN word
FFLNK:	BLOCK 1				; first free link

; Pointers to IMP tables are indexed up by 1, so RH is addr-1

LNKTAB:	(X)				; host-link number
IMPDDB:	(X)				; address of DDB
IMPLS:	(X)				; local socket number
IMPFS:	(X)				; foreign socket number
IMPSTB:	(X)				; link status
SUBTTL Initialization

LOGGER:	JFCL
	RESET
	SETZB CORBEG
	MOVE A,[CORBEG,,CORBEG+1]
	BLT A,COREND

; Diddle privileges

	GETPRV
	TLO (REAPRV\WRTPRV\ACWPRV\LUPPRV); want REA+WRT+ACW+LUP
	SETPRV
	TLC (REAPRV\WRTPRV\ACWPRV\LUPPRV)	
	TLCN (REAPRV\WRTPRV\ACWPRV\LUPPRV)	
	 JRST LOGGR1
	SETOM NOPRVP			; screwed by privileges!
	OUTSTR [ASCIZ/Un/]
	TLNE (REAPRV\WRTPRV\ACWPRV)	
	 OUTSTR [ASCIZ/der/]
	OUTSTR [ASCIZ/privileged /]
LOGGR1:	OUTSTR [ASCIZ/LOGGER started
/]

; Check for others

	MOVE [SIXBIT/[LOGR]/]
	SETNAM
	NAMEIN
	 JRST [	SETZ
		SETNAM
		OUTSTR [ASCIZ/There is another logger!/]
		EXIT]
	MOVE P,[PDL(-PDLLEN)]
; (continued on next page)
SUBTTL Set up monitor pointers

; Snarf up some monitor symbols

	MOVEI [.RSQZ 0,FFLNK ? 0]
	.SYML 
	 JRST 4,.-1
	ADDI 400000
	MOVEM FFLNK
	IRPS SYM,,LNKTAB IMPDDB IMPLS IMPFS IMPSTB
	 MOVEI [.RSQZ 0,SYM ? 0]
	 .SYML 
	  JRST 4,.-1
	 ADDI 377777
	 HRRM SYM
	TERMIN

; Map the monitor in

	MOVSI 377776
	SETPR2
	 JRST 4,.-1

; Get pointer to our JBTLIN entry

	MOVE A,400226			; addr of JOB
	MOVE A,400000(X)		; C(JOB)
	ADD A,400236			; JBTLIN table entry
	ADDI A,400000
	MOVEM A,JBTLIN

; Set up interrupts

	MOVEI [DISMIS]
	MOVEM JOBAPR
	MOVSI (INTIMS)
	INTENB
	JRST RFCSER			; scan through at least once

; Really a sleeper

SLEEPR:	IWAIT
;	JRST RFCSER
SUBTTL RFC server

; Scan monitor tables for an interesting RFC

RFCSER:	MOVE X,@FFLNK			; set up pointer to links
CHKLNK:	SKIPE @IMPDDB			; ignore links with a DDB
	 JRST NXTLNK
	MOVE @IMPSTB			; get status of this link
	TLNE (RFCR)			; somebody listening?
	 TLNE (RFCS\CLSR\CLSS\LGONCE)	; link already been munged?
	  JRST NXTLNK
	MOVSI (LGONCE)
	SKIPN NOPRVP
	 IORM @IMPSTB			; flag we've looked at the link

; Got an RFC with nobody serving it.  Make sure it is interesting.

	MOVE @IMPLS			; get socket for this link
	CAIGE 400			; public socket?
	 TRNN 1				; and heterosocketual?
	  JRST NXTLNK

; Save the info about this connection on the stack

	PUSH P,@IMPFS
	PUSH P,@IMPLS
	PUSH P,@LNKTAB

; Convert the socket number to sixbit

	LSHC -6				; separate 3 digits by three bits
	LSH 3
	LSHC 3
	LSH 3
	LSHC 3
	ADDI '000			; form sixbit socket number

; Now fire up the server

	HRRM SVRNAM
	MOVEI SWPBLK
	SWAP				; fire up the server

; Log the RFC

	MOVE @JBTLIN
	AOJE NXTLNK			; forget about logging if detached
	JUMPE [	OUTSTR [ASCIZ/Ign RFC/]
		JRST CONMSG]		; couldn't fire up phantom
	OUTSTR [ASCIZ/RFC j=/]		; server job
	PUSHJ P,DECOUT
CONMSG:	OUTSTR [ASCIZ/, hst=/]		; host number
	LDB [101017,,]
	PUSHJ P,OCTOUT
	OUTSTR [ASCIZ/, lnk=/]		; link number
	POP P,
	ANDI 377
	PUSHJ P,DECOUT
	OUTSTR [ASCIZ/, lsk=/]		; local socket number
	POP P,
	PUSHJ P,OCTOUT
	OUTSTR [ASCIZ/, fsk=/]		; foreign socket number
	POP P,
	PUSHJ P,OCTOUT
	OUTSTR [ASCIZ/.
/]

; Check next link

NXTLNK:	SOJG X,CHKLNK			; try next link
	JRST SLEEPR			; done scanning
SUBTTL Subroutines

; Decimal/octal print routine

DECOUT:	SKIPA B,[10.]			; decimal print
OCTOUT:	 MOVEI B,8.			; octal print
NUMOUT:	IDIVI (B)
	PUSH P,A
	SKIPE
	 PUSHJ P,NUMOUT
	POP P,
	ADDI "0
	OUTCHR
	POPJ P,

END LOGGER